#!/bin/bash
###############################################
# File Name :ops-run 
# Version : V1.0
# Auther : aurelianliu@tencent.com
# Organization : NULL
###############################################
GREEN='\033[1;32m'
RED='\033[1;31m'
BLUE='\033[1;34m'
NC='\033[0m'

drop_caches=0
mem_cost_topn=3

usage="\
Usage:
	oc-ops mem xfs_recover [-d dev] [-h]
	COMMAND-LINE Options:
	-d	block dev to recover
	-h	help: recover xfs fs
"

function strstr()
{
        echo $1 | grep $2
}

function main()
 {
	while getopts 'd;h' OPT; do
		case $OPT in
			d)      dev="$OPTARG"
				;;
			h)      echo "$usage"
				cat /usr/lib/opencloudos-tools/ops/fs/xfs_recover/README.md
				exit $?
				;;
			?)      echo "Invalid option: $OPT" >&2
				echo "$usage"
				exit 1
				;;
		esac
	done
	sub=$(strstr "rpm -qa"  "libtool")
	if [ -z "$sub" ]; then
	  yum install -y libtool
	fi
	sub=$(strstr "rpm -qa"  "libuuid")
	if [ -z "$sub" ]; then
	  yum install -y libuuid
	fi
	sub=$(strstr "rpm -qa"  "libuuid-devel")
	if [ -z "$sub" ]; then
	  yum install -y libuuid-devel
	fi
	sub=$(strstr "rpm -qa"  "libblkid-devel")
	if [ -z "$sub" ]; then
	  yum install -y libblkid-devel
	fi
	cd /usr/lib/opencloudos-tools/ops/fs/xfs_recover/
	make
	/usr/lib/opencloudos-tools/ops/fs/xfs_recover/recover/xfsrecover $dev
	cd -
 }

 main $*
